package ru.algorithm.clusterization.cftree2;

import java.util.Arrays;

/**
 * Yuri Zemlyanskiy <urikz@yandex-team.ru>
 * Date: 05.05.2011
 */
public class CFLeaf extends AbstractCFNode {
    private final double[] point;

    public CFLeaf(double[] point) {
        this.point = Arrays.copyOf(point, point.length);
    }

    @Override
    public int getPointNumber() {
        return 1;
    }

    @Override
    public double[] getSum() {
        return point;
    }

    @Override
    public double[] getSum2() {
        final double[] result = new double[point.length];
        for (int i = 0; i < point.length; i++) {
            result[i] = point[i] * point[i];
        }
        return result;
    }

    @Override
    public boolean equals(Object o) {
        if (o instanceof CFLeaf) {
            CFLeaf entry = (CFLeaf) o;
            return (point == entry.point);
        } else {
            return false;
        }
    }
}
